package com.applet.mallappletbackstage.service.impl;

import com.applet.mallappletbackstage.entity.ProjectExperience;
import com.applet.mallappletbackstage.entity.User;
import com.applet.mallappletbackstage.mapper.ProjectExperienceMapper;
import com.applet.mallappletbackstage.service.ProjectExperienceService;
import com.applet.mallappletbackstage.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.expression.spel.ast.OpNE;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author X
 * @since 2020-08-17
 */
@Service
public class ProjectExperienceServiceImpl extends ServiceImpl<ProjectExperienceMapper, ProjectExperience> implements ProjectExperienceService {

    @Autowired
    private UserService userService;

    /***
     * 添加项目经验
     * @param openid
     * @param projectExperience
     * @return
     */
    @Override
    public int addProject(String openid, ProjectExperience projectExperience) {
        User user = userService.getInfo(openid);
        String userId = user.getId();
        projectExperience.setUserId(userId);
        projectExperience.setOpenId(openid);
        return baseMapper.insert(projectExperience);
    }

    /***
     * 查询数据库是否有该用户数据
     * @param openid
     * @return
     */
    @Override
    public List<ProjectExperience> getProject(String openid) {
        QueryWrapper<ProjectExperience> projectExperienceQueryWrapper = new QueryWrapper<>();
        projectExperienceQueryWrapper.eq("open_id", openid);
        List<ProjectExperience> projectExperiences = baseMapper.selectList(projectExperienceQueryWrapper);
        return projectExperiences;
    }

    /***
     * 删除项目经验
     * @param id
     * @return
     */
    @Override
    public int deleteProject(String id) {
        QueryWrapper<ProjectExperience> projectExperienceQueryWrapper = new QueryWrapper<>();
        projectExperienceQueryWrapper.eq("id",id);
        return baseMapper.delete(projectExperienceQueryWrapper);
    }
}
